package com.ssy.lingxi.product.entity.channelCommodity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.api.model.request.commodity.LogisticsRequest;
import com.ssy.lingxi.product.handler.converter.JpaJsonToLogisticsConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 渠道会员
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/7/13
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_channel_commodity_member")
public class ChannelCommodityMember implements Serializable {
    private static final long serialVersionUID = 8763459285155819914L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="channel_member_seq")
    @SequenceGenerator(sequenceName="product_channel_member_seq", name="channel_member_seq",allocationSize = 1)
    private Long id;

    /**
     * 渠道商品
     */
    @JsonIgnore
    @ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="channelCommodityId",referencedColumnName = "id")
    private ChannelCommodity channelCommodity;

    /**
     * 渠道商品状态: 5-上架, 6-下架, 7-未上架
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer status = 7;

    /**
     * 渠道会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 渠道会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 渠道会员类型名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String memberTypeName;

    /**
     * 渠道会员角色id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberRoleId;

    /**
     * 渠道会员角色名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberRoleName;

    /**
     * 税率
     */
    @Column(columnDefinition = "decimal")
    private Double taxRate = 0d;

    /**
     * 是否允许使用会员折扣价购买
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isMemberPrice;

    /**
     * 最小(价格/积分)
     */
    @Column(columnDefinition = "decimal")
    private Double min;

    /**
     * 最大(价格/积分)
     */
    @Column(columnDefinition = "decimal")
    private Double max;

    /**
     * 渠道商品单价
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "channelCommodityMember", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<ChannelCommodityUnitPricePic> unitPriceAndPicList;

    /**
     * 渠道会员商品发布商城
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "channelCommodityMember", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<ChannelCommodityShop> shopList;

    /**
     * 上架时间
     */
    @Column(columnDefinition = "int8")
    private Long publishTime;

    /**
     * 店铺id
     */
    @Column(columnDefinition = "int8")
    private Long storeId;

    /**
     * 物流信息
     */
    @Convert(converter = JpaJsonToLogisticsConverter.class)
    @Column(columnDefinition="jsonb")
    private LogisticsRequest logistics;
}
